$(document).ajaxSend(function (e, xhr, opt) {
    var user_token = localStorage.getItem("user_token");
    xhr.setRequestHeader("user_token_header", user_token);
});



$(document).ajaxError(function(event, jqxhr, settings, thrownError) {
    console.log(jqxhr.status)
    // 在这里处理所有Ajax请求的错误
    if (jqxhr.status === 401) {
        // 如果状态码为401，执行跳转操作
        alert("用户未登录")
        window.location.href = "blog_login.html";
    } else {
        // 其他错误处理
        console.error('请求失败', thrownError);
    }
});


function getUserInfo(url) {
    $.ajax({
        type: "get",
        url: url,
        success: function (result) {
            if (result.code == 200 && result.data != null) {
                $(".left .card h3").text(result.data.userName);
                $(".left .card a").attr("href", result.data.githubUrl);
            }
        }
    });
}

function logout(){
    localStorage.removeItem("user_token");
    location.href = "blog_login.html";
}